//
//  YLNavigationController.m
//  YLFinanceService
//
//  Created by she1323 on 2017/8/16.
//  Copyright © 2017年 she1323. All rights reserved.
//

#import "YLNavigationController.h"
#import "YLGlobeHeader.h"
#import "WHNavBackButton.h"
//#import "uico"
@interface YLNavigationController ()<UIGestureRecognizerDelegate,UINavigationControllerDelegate, UIImagePickerControllerDelegate>
@property(nonatomic,weak) UIViewController *currentShowVC;

@end

@implementation YLNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 设置navbar的颜色
    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navBackground"] forBarMetrics:UIBarMetricsDefault];
   // self.navigationBar.tintColor = [UIColor clearColor];
   // [UINavigationBar appearance].tintColor = [UIColor orangeColor];
//    [self.navigationBar insertSubview:A atIndex:0];
 
    
    // 修改标题颜色
    self.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};
    // 修改状态栏颜色
    self.navigationBar.barStyle = UIStatusBarStyleLightContent;
    
    //self.navigationBar.barTintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:   @"navBackground"]];
    
    // 设置整个项目所有item的主题样式
    UIBarButtonItem *item = [UIBarButtonItem appearance];
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = YLGayColor;
    textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:15];
    [item setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (instancetype)initWithRootViewController:(UIViewController *)rootViewController
{
    YLNavigationController *nvc= [super initWithRootViewController:rootViewController];
    self.interactivePopGestureRecognizer.delegate = self;
    nvc.delegate = self;
    return nvc;
}

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (navigationController.viewControllers.count == 1)
        self.currentShowVC = Nil;
    else
        self.currentShowVC = viewController;
}

-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    if (gestureRecognizer == self.interactivePopGestureRecognizer) {
        return (self.currentShowVC == self.topViewController);
    }
    return YES;
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    
    if (self.childViewControllers.count) {
        viewController.hidesBottomBarWhenPushed = YES;
        WHNavBackButton *backButton = [WHNavBackButton navBackButton];
        [backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    }
    
    [super pushViewController:viewController animated:animated];
    
}

- (void)back
{
    [self popViewControllerAnimated:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
